// pages/details/details.js
const httpRequest = require('../../utils/http_utils.js')
const dateutil = require('../../utils/date_util.js')
const common = require('../../utils/common.js')
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    dataList: [], //数据集合
    WorkOrderId: '',
    WorkOrderState: '',
    WorkType: '',
    WorkTime: '',
    RepairTime: '',
    RepairPerson: '',
    RepairPersonTel: '',
    WorkPlaceRoomNames: '',
    FailureType: '',
    Description: '',
    WorkPlace: '',
    WorkOrderStateName: '',
    IsCharge: '',
    WorkOrdersFlow: [], //进度信息
    score: 0, //评价星级
    WorkOrdersImgTable: [], //工单附件
    Remark: '', //工单维修记录 备注
    Expenses: '', //工单维修记录 费用
    Qianming: '', //工单维修记录 签名
    RowGuid: '', //传参
    UploadUrl: httpRequest.uploadUrl,
    showchexiaogongdan: false, //撤销工单
    dialogShows: false,
    buttone: [{
      text: '保存'
    }],
    test: '', //备注input值
    success: '', //成功提示信息
    error: '', //失败提示信息
    zhuanpai: false, //转派
    zhipai: false, //指派
    LeaderGuid_B: '', //分配人员guid
    LeaderName_B: '', //分配人员name
    dialogShow: false,
    buttons: [{
      text: '取消'
    }, {
      text: '确定'
    }],
    info: '',
    // imgs: [],
    // imgsRepair: [],
    // newrewImg: [],
    Repair: false, //维修判断
    RepairArray: [],
    newrewArray: [],
    NamesArray: [],
    showjieshou: false, //显示接受和不接受
    noShow: false, //是否显示不接受备注
    showchuli: false, //是否显示处理
    noButton: [{
      text: '提交'
    }],
    bujieshou_Remark: '', //不接受备注
    judgeImg: false, //判断显示图片
    showshenhe: false, //判断是否显示通过/不通过
    noPassage: false, //显示不通过
    noBut: [{
      text: '提交'
    }],
    failpass_Remark: '', //审核不通过备注
    picnum: 0, //图片上传数量
    FileGuid: [], //上传图片参数集合
    images: [], //图片集合
    showpingjia: false,
    starpingjia: false,
    pingjia_time: '', //评价时间
    starremark: '', //评价备注
    curstarindex: '5', //当前评价5颗星
    title: '工单详情',
    scrollHeight: 0,
    // directorName: '', //主管名字
    DisplayName: '', //当前登录人的展示名
    imgs2: [], //用于过渡图片地址和rowguid关系
    chargeList: [{
        name: '否',
        value: 0,
        checked: 'true'
      },
      {
        name: '是',
        value: 1
      }
    ], //是否收费
    Customer: false, //是否显示收费提示
    Charges: 0, //是否收费
    AssignPersonnel: '', //主管所指派的人员
    ReasonItems: [], //撤销原因选项
    RevokeCause: '', //撤销原因
    equipName: '', // 报修设备名称
    OuGuid:'', //部门ID
  },

  //计算 scroll-view 的高度
  computeScrollViewHeight() {
    let that = this;
    this.setData({
      scrollHeight: (app.globalData.titleBarHeight + app.globalData.statusBarHeight) * 2
    })
    // let screenHeight = wx.getSystemInfoSync().windowHeight
    // let scrollHeight = screenHeight - 68;
    // that.setData({
    //   scrollHeight: scrollHeight
    // })
  },

  //初始化数据
  initData: function() {
    var that = this;
    var param = {
      // WorkOrdersGuid:"84da6ae0-ca30-4b8b-95fe-0930f178dbb6"
      // WorkOrdersGuid: "bbf31eb6-94b1-4306-af56-b9d8ea20edce"
      WorkOrdersGuid: that.data.RowGuid
    }
    try {
      httpRequest.GetValidateRequest(httpRequest.apiInfo.GetWorkOrderInfoApi, param, function(data) {
        console.log(JSON.stringify(data) + "____________接口返回数据")
        if (data != null || data != "" || data != undefined) {
          // console.log(JSON.stringify(data.Data.WorkOrdersImgTable) + '--------图片集合')
          // var newarray = new Array();
          // for (var i = 0; i < data.Data.WorkOrdersImgTable.length; i++) {
          //   newarray.push(that.data.UploadUrl + data.Data.WorkOrdersImgTable[i].FilePath)
          // }
          // that.setData({
          //   imgs: newarray
          // })
          that.setData({
            WorkOrderId: data.Data.WorkOrdersInfo.WorkOrderId,
            WorkOrderState: data.Data.WorkOrdersInfo.WorkOrderState,
            WorkType: data.Data.WorkOrdersInfo.WorkType,
            WorkTime: data.Data.WorkOrdersInfo.WorkTime,
            RepairTime: data.Data.WorkOrdersInfo.RepairTime,
            RepairPerson: data.Data.WorkOrdersInfo.RepairPerson,
            RepairPersonTel: data.Data.WorkOrdersInfo.RepairPersonTel,
            WorkPlaceRoomNames: data.Data.WorkOrdersInfo.WorkPlaceRoomNames,
            BusinessName: data.Data.WorkOrdersInfo.BusinessName,
            FailureType: data.Data.WorkOrdersInfo.FailureType,
            Description: data.Data.WorkOrdersInfo.Description,
            WorkPlace: data.Data.WorkOrdersInfo.WorkPlace,
            WorkOrderStateName: data.Data.WorkOrdersInfo.WorkOrderStateName,
            IsCharge: data.Data.WorkOrdersInfo.IsCharge,
            equipName: data.Data.WorkOrdersInfo.equipName,
          })

          console.log(JSON.stringify(data.Data.WorkOrdersInfo.FailureType))

          if (data.Data.WorkOrdersFlow.length > 0) {
            // that.data.WorkOrdersFlow = data.Data.WorkOrdersFlow;
            var newarr = new Array();
            var nameArr = new Array();
            var newrew = new Array();
            for (var i = 0; i < data.Data.WorkOrdersFlow.length; i++) {
              var FlowName = 'WorkOrdersFlow[' + i + '].FlowName';
              var FlowNames = 'WorkOrdersFlow[' + i + '].FlowNames';
              var WorkOrderState = 'WorkOrdersFlow[' + i + '].WorkOrderState';
              var CreateTime = 'WorkOrdersFlow[' + i + '].CreateTime';
              var FileListData = 'WorkOrdersFlow[' + i + '].FileListData';
              var FilePath = 'WorkOrdersFlow[' + i + '].FilePath';
              var RecordContent = 'WorkOrdersFlow[' + i + '].RecordContent'
              var Remark = 'WorkOrdersFlow[' + i + '].Remark'
              var Expenses = 'WorkOrdersFlow[' + i + '].Expenses'
              var LaborFees = 'WorkOrdersFlow[' + i + '].LaborFees'
              var MaterialFees = 'WorkOrdersFlow[' + i + '].MaterialFees'
              that.setData({
                [FlowName]: dateutil.flownameformat(data.Data.WorkOrdersFlow[i].FlowName, data.Data.WorkOrdersFlow[i].WorkOrderState),
                [FlowNames]: data.Data.WorkOrdersFlow[i].FlowName,
                [WorkOrderState]: data.Data.WorkOrdersFlow[i].WorkOrderState,
                [FileListData]: data.Data.WorkOrdersFlow[i].FileListData,
                [FilePath]: data.Data.WorkOrdersFlow[i].FilePath,
                [CreateTime]: data.Data.WorkOrdersFlow[i].CreateTime,
                [RecordContent]: data.Data.WorkOrdersFlow[i].RecordContent,
                [Remark]: data.Data.WorkOrdersFlow[i].Remark,
                [Expenses]: data.Data.WorkOrdersFlow[i].Expenses,
                [LaborFees]: data.Data.WorkOrdersFlow[i].LaborFees,
                [MaterialFees]: data.Data.WorkOrdersFlow[i].MaterialFees
              })
              if (data.Data.WorkOrdersFlow[i].FlowName.indexOf('维修记录') != -1 &&
                data.Data.WorkOrdersFlow[i].PicUrl != null && data.Data.WorkOrdersFlow[i].PicUrl != null) {
                that.setData({
                  Qianming: data.Data.WorkOrdersFlow[i].PicUrl
                })
              }

              var Names = false;
              if (data.Data.WorkOrdersFlow[i].FlowName.indexOf('评价') != -1) {
                console.log("判断是否有评价" + data.Data.WorkOrdersFlow[i].FlowName.indexOf('评价'))
                var num = parseInt(
                  data.Data.WorkOrdersFlow[i].FlowName.substring(data.Data.WorkOrdersFlow[i].FlowName.length - 1),
                  data.Data.WorkOrdersFlow[i].FlowName.length
                );
                that.setData({
                  score: num
                })
                Names = true;
              } else {
                Names = false;
              }
              var par = {
                Names: Names
              }
              nameArr.push(par);
              that.setData({
                NamesArray: nameArr
              })


              var issrepair = false;
              if (data.Data.WorkOrdersFlow[i].FlowName.indexOf('维修记录') != -1) {
                // if (data.Data.WorkOrdersFlow[i].FileListData.length > 0) {
                //   var newarrayRepair = new Array();
                //   for (var j = 0; j < data.Data.WorkOrdersFlow[i].FileListData.length; j++) {
                //     newarrayRepair.push(that.data.UploadUrl + data.Data.WorkOrdersFlow[i].FileListData[j].FilePath)
                //   }
                //   that.setData({
                //     imgsRepair: newarrayRepair
                //   })
                // }
                issrepair = true
              } else {
                issrepair = false
              }
              var param = {
                issrepair: issrepair
              }
              // console.log("维修记录" + issrepair)
              newarr.push(param)

              var Rework = false;
              if ((data.Data.WorkOrdersFlow[i].FilePath != null || data.Data.WorkOrdersFlow[i].FilePath != "" || data.Data
                  .WorkOrdersFlow[i].FilePath != undefined) && data.Data.WorkOrdersFlow[i].FlowName.indexOf('工单返修') != -1) {
                // that.setData({
                //   newrewImg: that.data.UploadUrl + data.Data.WorkOrdersFlow[i].FileListData[i].FilePath
                // })
                Rework = true;
              } else {
                Rework = false;
              }
              var par = {
                Rework: Rework
              }
              console.log("工单返修" + JSON.stringify(Rework))
              newrew.push(par);


              // if (data.Data.WorkOrdersFlow[i].WorkOrderState == '6' || data.Data.WorkOrdersFlow[i].WorkOrderState == 6) {
              //   // data.Data.WorkOrdersFlow[i].FlowName
              //   var str = data.Data.WorkOrdersFlow[i].FlowName;
              //   var director = str.substring(str.lastIndexOf(':') + 1, str.lastIndexOf(',') - 1);
              //   that.setData({
              //     directorName: director
              //   })
              // }

              //获取工程主管所指派的人员名字
              if (data.Data.WorkOrdersFlow[i].WorkOrderState == '5' || data.Data.WorkOrdersFlow[i].WorkOrderState == 5) {

                // data.Data.WorkOrdersFlow[i].FlowName
                var str = data.Data.WorkOrdersFlow[i].FlowName;
                var director = str.substring(str.lastIndexOf(':') + 1, str.length - 1);
                that.setData({
                  AssignPersonnel: director
                })
                console.log(that.data.AssignPersonnel + "---------------------截取出来的人员名字")
              }

            }
            that.setData({
              RepairArray: newarr
            })
            that.setData({
              newrewArray: newrew
            })
            // console.log("RepairArray", that.data.RepairArray)
            console.log(that.data.score + "___________星级评价")
            if (data.Data.WorkOrdersFlow.FileListData == '' || data.Data.WorkOrdersFlow.FileListData == null || data.Data
              .WorkOrdersFlow.FileListData == []) {
              that.setData({ //判断是否显示图片
                judgeImg: false
              })
            } else {
              that.setData({
                judgeImg: true
              })
            }
          } else {
            that.WorkOrdersFlow = [];
          }

          if (wx.getStorageSync("UserInfo").AppLogin.RoleName == '客服人员' && wx.getStorageSync("UserInfo").AppLogin.IsOuManager == 0) { //判断撤销
            console.log(that.data.WorkOrderState + "__________状态值")
            if (that.data.WorkOrderState != '1' && that.data.WorkOrderState != '9' && that.data.WorkOrderState != '10' &&
              that.data.WorkOrderState != '4') {
              //显示按钮时高度减45px
              var scrollHeight = that.data.scrollHeight;
              console.log(scrollHeight)
              that.setData({
                scrollHeight: scrollHeight + 90
              })
              that.setData({
                showchexiaogongdan: true
              })
            }
          }
          console.log(that.data.WorkOrderState + "------------------" + wx.getStorageSync("UserInfo").AppLogin.IsOuManager)
          if (wx.getStorageSync('UserInfo').AppLogin.RoleName == '客服人员') {
            if (that.data.WorkOrderState == '1' && wx.getStorageSync("UserInfo").AppLogin.IsOuManager == '0') {
              //显示按钮时高度减45px
              var scrollHeight = that.data.scrollHeight;
              console.log(scrollHeight)
              that.setData({
                scrollHeight: scrollHeight + 90
              })
              that.setData({
                zhuanpai: true,
                Customer: true
              })
            }
            //客服显示评价按钮
            else if (that.data.WorkOrderState == '4' && that.data.WorkType != '租户报修') {
              //显示按钮时高度减45px
              var scrollHeight = that.data.scrollHeight;
              console.log(scrollHeight)
              that.setData({
                scrollHeight: scrollHeight + 90
              })
              that.setData({
                showpingjia: true
              })
            }

          } else if (wx.getStorageSync('UserInfo').AppLogin.IsOuManager == '1' && that.data.OuGuid == '3a9bb417-2ae6-dee7-7bff-a4420a139929') {
            if (that.data.WorkOrderState == '6') {
              //显示按钮时高度减45px
              var scrollHeight = that.data.scrollHeight;
              console.log(scrollHeight)
              that.setData({
                scrollHeight: scrollHeight + 90
              })
              that.setData({
                zhipai: true,
                Customer: false
              })
            } else if (that.data.WorkOrderState == '11') {
              //显示按钮时高度减45px
              var scrollHeight = that.data.scrollHeight;
              console.log(scrollHeight)
              that.setData({
                scrollHeight: scrollHeight + 90
              })
              that.setData({
                showshenhe: true
              })
            }
          }

          //判断工单附件集合是否大于0
          if (data.Data.WorkOrdersImgTable.length > 0) {
            that.data.WorkOrdersImgTable = data.Data.WorkOrdersImgTable;
            for (var i = 0; i < data.Data.WorkOrdersImgTable.length; i++) {
              var FilePath = 'WorkOrdersImgTable[' + i + '].FilePath';
              that.setData({
                [FilePath]: data.Data.WorkOrdersImgTable[i].FilePath,
              })
            }
          } else {
            that.WorkOrdersImgTable = [];
          }

          //维修记录集合是否大于0
          // if (data.Data.RepairRecord.length > 0) {
          //   // that.data.Remark = data.Data.RepairRecord[0].Remark; //工单维修记录 备注
          //   // that.data.Expenses = data.Data.RepairRecord[0].Expenses; //工单维修记录 费用
          //   // that.data.Qianming = data.Data.RepairRecord[0].PicUrl; //工单维修记录 签名
          //   for (var i = 0; i < data.Data.RepairRecord.length; i++) {
          //     if (data.Data.RepairRecord[i].IsRepair == '1') {
          //       that.setData({
          //         Qianming: data.Data.RepairRecord[i].PicUrl,
          //         // Expenses: data.Data.RepairRecord[i].Expenses,
          //         // Remark: data.Data.RepairRecord[i].Remark
          //       })
          //     }
          //   }
          // }
          // console.log(that.data.Qianming + "____________签名")
          // console.log(that.data.Expenses + "____________费用")
          // console.log(that.data.Remark + "____________备注")
          console.log(wx.getStorageSync('UserInfo').AppLogin.IsOuManager + "-------------------------缓存")
          if (that.data.DisplayName == that.data.AssignPersonnel && wx.getStorageSync('UserInfo').AppLogin.IsOuManager == '1') {
            console.log(that.data.AssignPersonnel + "____________主管备注")
            console.log(that.data.DisplayName + "____________主管备注")
            console.log("____________主管接受")
            if (that.data.WorkOrderState == '5') {
              //显示按钮时高度减45px
              var scrollHeight = that.data.scrollHeight;
              console.log(scrollHeight)
              that.setData({
                scrollHeight: scrollHeight + 90
              })
              that.setData({
                showjieshou: true
              })
            } else if (that.data.WorkOrderState == '3' || that.data.WorkOrderState == '2') { //判断显示处理按钮
              console.log("____________主管处理")
              //显示按钮时高度减45px
              var scrollHeight = that.data.scrollHeight;
              console.log(scrollHeight)
              that.setData({
                scrollHeight: scrollHeight + 90
              })
              that.setData({
                showchuli: true
              })
            }
          }

          if (wx.getStorageSync("UserInfo").AppLogin.RoleName == '工程人员' && wx.getStorageSync('UserInfo').AppLogin.IsOuManager != '1') { //判断显示接受/不接受按钮
            if (that.data.WorkOrderState == '5') {
              //显示按钮时高度减45px
              var scrollHeight = that.data.scrollHeight;
              console.log(scrollHeight)
              that.setData({
                scrollHeight: scrollHeight + 90
              })
              that.setData({
                showjieshou: true
              })
            } else if (that.data.WorkOrderState == '3' || that.data.WorkOrderState == '2' && wx.getStorageSync('UserInfo').AppLogin.IsOuManager != '1') { //判断显示处理按钮
              //显示按钮时高度减45px
              var scrollHeight = that.data.scrollHeight;
              console.log(scrollHeight)
              that.setData({
                scrollHeight: scrollHeight + 90
              })
              that.setData({
                showchuli: true
              })
            }
          }
        }
      }, function(err) {
        console.log(JSON.stringify(err))
      })
    } catch (e) {
      console.log(JSON.stringify(e))
    }
  },

  callMe: function(e) { //获取手机号
    console.log(e.currentTarget.dataset.phone)
    wx.makePhoneCall({
      phoneNumber: e.currentTarget.dataset.phone
    })
  },

  Revoke: function() { //显示撤销按钮
    this.setData({
      dialogShows: true
    })
    //获取撤销原因
    this.GetKeyWords();
  },

  tapDialogButtons(e) { //撤销工单
    var that = this;
    if (that.data.RevokeCause == '') {
      that.setData({
        info: '请选择撤销原因'
      })
      return false;
    }
    that.setData({
      dialogShows: false,
    })
    var param = {
      WorkOrderGuid: that.data.RowGuid,
      ProjectGuid: wx.getStorageSync("UserInfo").AppLogin.ProjectGuid,
      Remark: that.data.test,
      RevokeCause: that.data.RevokeCause
    }
    console.log(JSON.stringify(param))
    httpRequest.PostValidateRequest(httpRequest.apiInfo.AddCxgdApi, param, function(data) {
      console.log(JSON.stringify(data) + "______撤销工单接口返回值")
      if (data == '0') {
        that.setData({
          success: '工单已撤销！'
        })


        var pages = getCurrentPages();
        let prevPage = pages[pages.length - 2];
        if (pages.length > 3) {
          prevPage.setData({
            currentTab: 6,
            state: 9
          })
          wx.navigateBack({
            delta: 1
          })
        } else {
          wx.navigateTo({
            url: '../workorderlist/workorderlist?currentTab=' + 6 + '&state=' + 9 + '&isshoworder=' + true,
          })
        }


      } else if (data == '1') {
        that.setData({
          info: '已经超过撤销时间！'
        })
      } else {
        that.setData({
          error: '工单撤销失败！'
        })
      }
    }, function(err) {})
  },

  bdinput: function(e) { //获取撤销备注
    console.log(e.detail.value)
    this.setData({
      test: e.detail.value
    })
  },

  fenpeirenyuan: function() { //转派/指派页面跳转
    if (this.data.zhuanpai == true){
      this.setData({
        dialogShow:true
      })
    }else{
      wx.navigateTo({
        url: '/pages/Watchman/Watchman',
      })
    }
    
  },

  tapDialogButton(e) { //人员分配
    var that = this
    if (that.data.zhuanpai == true) {
      var WorkState = '6';
    } else if (that.data.zhipai == true) {
      var WorkState = '5';
    }

    console.log('dialog', e.detail)
    if (e.detail.index == 0) {
      that.setData({
        dialogShow: false,
        info: '已取消分配操作!'
      })
    } else {
      that.setData({
        dialogShow: false
      })
      var param = {
        RowGuid: that.data.RowGuid,
        leaderRowGuid: that.data.LeaderGuid_B,
        leader: that.data.LeaderName_B,
        FormatName: wx.getStorageSync('UserInfo').AppLogin.FormatName,
        WorkOrderState: WorkState,
        IsCharge: that.data.Charges
      };
      console.log(param)
      httpRequest.PostValidateRequest('api/LanShengMobile/UpdateFpRecord', param,
        function(res) {
          console.log(res)
          if (res == '0') {
            that.setData({
              success: '分配成功'
            })
            if (that.data.zhuanpai == true) {
              //未分配


              var pages = getCurrentPages();
              let prevPage = pages[pages.length - 2];
              if (pages.length > 3) {
                prevPage.setData({
                  currentTab: 1,
                  state: 6
                })
                wx.navigateBack({
                  delta: 1
                })
              } else {
                wx.navigateTo({
                  url: '/pages/workorderlist/workorderlist?currentTab=1&state=6&isshoworder=true'
                })
              }


            } else if (that.data.zhipai == true) {
              //未接受


              var pages = getCurrentPages();
              let prevPage = pages[pages.length - 2];
              if (pages.length > 3) {
                prevPage.setData({
                  currentTab: 2,
                  state: 5
                })
                wx.navigateBack({
                  delta: 1
                })
              } else {
                wx.navigateTo({
                  url: '/pages/workorderlist/workorderlist?currentTab=2&state=5&isshoworder=true'
                })
              }


            }
          } else if (res == '2') {
            that.setData({
              error: '不能同时分配给同一个工程人员'
            })
          } else if (res == '4'){
            if (that.data.zhuanpai == true) {
              that.setData({
                info: '无法转派，当前工单已被转派！'
              })
            } else if (that.data.zhipai == true) {
              that.setData({
                info: '无法指派，当前工单已被指派！'
              })
            }
            
          } else {
            that.setData({
              error: '分配失败'
            })
          }
        },
        function(err) {
          console.error(err)
          that.setData({
            error: '分配失败'
          })
        }
      )
    }
  },

  // //预览图片
  // previewImg: function(e) {
  //   console.log(e)
  //   let imgtype = e.currentTarget.dataset.imgtype;
  //   let index = e.currentTarget.dataset.index;
  //   let imgs = null;
  //   if (imgtype == "work") {
  //     imgs = this.data.imgs;
  //   } else if (imgtype == "repair") {
  //     imgs = this.data.imgsRepair
  //   } else if (imgtype == "newrews") {
  //     imgs = this.data.newrewImg
  //   }
  //   wx.previewImage({
  //     current: imgs[index],
  //     urls: imgs,
  //   })
  // },

  //预览图片
  previewImg: function(e) {
    console.log(e)
    // let imgtype = e.currentTarget.dataset.imgtype;
    let imglist = e.currentTarget.dataset.imglist
    let index = e.currentTarget.dataset.index;
    let imgs = [];
    console.log(imglist)
    for (var i = 0; i < imglist.length; i++) {
      imgs.push(this.data.UploadUrl + imglist[i].FilePath)
    }
    console.log(imgs)
    wx.previewImage({
      current: imgs[index],
      urls: imgs,
    })
  },

  //接受工单
  jieshou: function() {
    var that = this;
    var param = {
      WorkOrdersGuid: that.data.RowGuid,
      WorkOrderState: '2',
      RecordContent: ''
    }
    console.log(JSON.stringify(param) + "_________________接受工单param")
    httpRequest.GetValidateRequest(httpRequest.apiInfo.AcceptWorkOrdersApi, param, function(data) {
      if (data == true) {
        that.setData({
          success: '工单接受成功！'
        })


        var pages = getCurrentPages();
        let prevPage = pages[pages.length - 2];
        if (pages.length > 3) {
          prevPage.setData({
            currentTab: 3,
            state: 3
          })
          wx.navigateBack({
            delta: 1
          })
        } else {
          wx.redirectTo({
            url: '../workorderlist/workorderlist?currentTab=' + 3 + '&state=' + 3 + '&isshoworder=' + true,
          })
        }


      } else {
        that.setData({
          error: '工单接受失败！'
        })
      }
    }, function(err) {})
  },

  Nojieshou: function() { //显示备注
    this.setData({
      noShow: true
    })
  },

  bujieshou: function() { //不接受工单
    var that = this;
    if (that.data.bujieshou_Remark == '' || that.data.bujieshou_Remark == null || that.data.bujieshou_Remark ==
      undefined) {
      that.setData({
        info: '请填写备注！'
      })
    } else {
      var param = {
        WorkOrdersGuid: that.data.RowGuid,
        WorkOrderState: '6',
        RecordContent: that.data.bujieshou_Remark
      }
      httpRequest.GetValidateRequest(httpRequest.apiInfo.AcceptWorkOrdersApi, param, function(data) {
        if (data == true) {
          that.setData({
            success: '工单不接受成功！'
          })


          var pages = getCurrentPages();
          let prevPage = pages[pages.length - 2];
          if (pages.length > 3) {
            prevPage.setData({
              currentTab: 2,
              state: 5
            })
            wx.navigateBack({
              delta: 1
            })
          } else {
            wx.redirectTo({
              url: '../workorderlist/workorderlist?currentTab=' + 2 + '&state=' + 5 + '&isshoworder=' + true,
            })
          }


        } else {
          that.setData({
            error: '工单不接受失败！'
          })
        }
      }, function(err) {})
    }

  },

  noInput: function(e) { //获取不接受工单备注内容
    this.setData({
      bujieshou_Remark: e.detail.value
    })
  },

  chuli: function() { //处理页面跳转
    wx.redirectTo({
      url: '../repairrecord/repairrecord?WorkOrderGuid=' + this.data.RowGuid + '&IsCharge=' + this.data.IsCharge,
    })
  },

  pass: function() { //通过审核
    var that = this;
    var param = {
      WorkOrdersGuid: that.data.RowGuid,
      WorkOrderState: '4',
      RecordContent: ''
    }
    console.log(JSON.stringify(param) + "_________________通过审核param")
    httpRequest.GetValidateRequest(httpRequest.apiInfo.AcceptWorkOrdersApi, param, function(data) {
      if (data == true) {
        that.setData({
          success: '工单审核成功！'
        })


        var pages = getCurrentPages();
        let prevPage = pages[pages.length - 2];
        if (pages.length > 3) {
          prevPage.setData({
            currentTab: 4,
            state: 11
          })
          wx.navigateBack({
            delta: 1
          })
        } else {
          wx.redirectTo({
            url: '../workorderlist/workorderlist?currentTab=' + 4 + '&state=' + 11 + '&isshoworder=' + true,
          })
        }


      } else {
        that.setData({
          error: '工单审核失败！'
        })
      }
    }, function(err) {})
  },

  Nopass: function() { //显示审核弹窗
    this.setData({
      noPassage: true
    })
  },

  butongguo: function() { //审核不通过提交
    var that = this;
    if (that.data.failpass_Remark == '' || that.data.failpass_Remark == null || that.data.failpass_Remark == undefined) {
      that.setData({
        info: '请填写备注！'
      })
    } else {
      var imgs2 = that.data.imgs2
      var temp = that.data.FileGuid
      if (imgs2.length > 0) {
        for (var i = 0; i < imgs2.length; i++) {
          var param1 = {
            RowGuid: imgs2[i].RowGuid,
            FileGuid: imgs2[i].FileGuid
          }
          temp.push(param1)
        }
        that.setData({
          FileGuid: temp
        })
        console.log('FileGuid------', that.data.FileGuid)
      }
      var param = {
        WorkOrdersGuid: that.data.RowGuid,
        WorkOrderState: '3',
        RecordContent: that.data.failpass_Remark,
        FileGuid: that.data.FileGuid
      }
      console.log(JSON.stringify(param) + "______________________接口传输参数")
      httpRequest.PostValidateRequest(httpRequest.apiInfo.NoAcceptWorkOrders, param, function(data) {
        if (data == 0) {
          that.setData({
            success: '工单不通过成功！'
          })


          var pages = getCurrentPages();
          let prevPage = pages[pages.length - 2];
          if (pages.length > 3) {
            prevPage.setData({
              currentTab: 3,
              state: 3
            })
            wx.navigateBack({
              delta: 1
            })
          } else {
            wx.redirectTo({
              url: '../workorderlist/workorderlist?currentTab=' + 3 + '&state=' + 3 + '&isshoworder=' + true, //审核不通过跳转至处理中
            })
          }


        } else {
          that.setData({
            error: '工单不通过失败！'
          })
        }
      }, function(err) {})
    }

  },

  PassageInput: function(e) { //获取审核不通过备注
    this.setData({
      failpass_Remark: e.detail.value
    })
  },

  uploads: function() { //图片压缩
    var that = this;
    // var fileRowGuid = that.data.FileGuid;
    var newImgs = that.data.images
    var imgs_2 = that.data.imgs2
    wx.chooseImage({
      count: 9 - that.data.images.length,
      sizeType: ['compressed'],
      sourceType: ['album', 'camera'],
      success: function(res) {
        const tempFilePaths = res.tempFilePaths;
        for (var i = 0; i < tempFilePaths.length; i++) {
          newImgs.push(tempFilePaths[i])
        }
        for (var i = 0; i < tempFilePaths.length; i++) {
          // newImgs.push(tempFilePaths[i])
          let path = tempFilePaths[i]
          //压缩图片
          wx.compressImage({
            src: tempFilePaths[i],
            quality: 80,
            success: function(res) {
              var tempimgpath = res.tempFilePath
              const uploadFile = wx.uploadFile({
                url: httpRequest.host + httpRequest.apiInfo.MultipleFileUploadMobileApi,
                filePath: tempimgpath,
                name: 'file',
                header: {
                  "Content-Type": "multipart/form-data"
                },
                formData: {
                  FileType: '维修记录'
                },
                success(res) {
                  console.log(JSON.stringify(res) + "__________服务器上传图片成功")
                  // var param = {
                  //   RowGuid: JSON.parse(res.data).RowGuid,
                  //   FileGuid: JSON.parse(res.data).FileGuid
                  // }
                  var param1 = {
                    path: path,
                    path2: tempimgpath,
                    RowGuid: JSON.parse(res.data).RowGuid,
                    FileGuid: JSON.parse(res.data).FileGuid
                  }
                  imgs_2.push(param1)
                  console.log(JSON.stringify(param1) + "___________________param")
                  // fileRowGuid.push(param);
                },
                fail: function(err) {
                  console.error(err + "图片上传失败")
                }
              })
              uploadFile.onProgressUpdate((res) => {
                // console.log("上传进度", res.progress)
                if (res.progress == 100) {
                  wx.hideLoading()
                } else {
                  wx.showLoading({
                    title: '图片已上传' + res.progress + '%',
                  })
                }
              })
            },
            fail: function(err) {
              console.error(('压缩图片失败', err))
            }
          })
        }


        that.setData({
          imgs2: imgs_2,
          images: newImgs,
          picnum: that.data.images.length,
          // FileGuid: fileRowGuid,
        })
        console.log('FileGuid', JSON.stringify(that.data.FileGuid))
      },
    })
  },

  PasUpload: function(e) { //删除图片
    var that = this;
    console.log(e.currentTarget.dataset.index + "___________下标显示")
    wx.showModal({
      title: '删除图片',
      content: '确定删除图片',
      confirmText: '删除',
      success: function(res) {
        if (res.confirm) {
          // let index = e.currentTarget.dataset.index;
          // let images = that.data.images;
          let index = e.currentTarget.dataset.index;
          let imgs_1 = that.data.images;
          let imgs_2 = that.data.imgs2;
          // console.log('删除前的imgs_2', imgs_2)
          let filepath = e.currentTarget.dataset.filepath
          for (var i = 0; i < imgs_2.length; i++) {
            if (imgs_2[i].path == filepath) {
              // console.log('要删除了啊', filepath)
              // console.log('index=' + index, 'i=' + i)
              var param = {
                RowGuid: imgs_2[i].RowGuid
              }
              // console.log('删除的RowGuid----', imgs_2[i].RowGuid)
              httpRequest.GetValidateRequest(httpRequest.apiInfo.MultipleFileDeleteMobileApi, param,
                function(res) {
                  console.log('删除的结果---', res)
                },
                function(err) {
                  console.error(err)
                })
              imgs_2.splice(i, 1)
            }
          }

          imgs_1.splice(index, 1)
          console.log('删除后的imgs---', imgs_1)
          console.log('删除后的imgs2---', imgs_2)
          // that.data.FileGuid.splice(index, 1)
          that.setData({
            images: imgs_1,
            imgs2: imgs_2,
            picnum: that.data.images.length
          })
        }
      }
    })
  },

  pingjia: function() { //显示评价弹窗
    this.setData({
      starpingjia: true
    })
  },

  choosestar: function(e) { //星星点击事件
    this.setData({
      curstarindex: e.currentTarget.dataset.star
    })
  },

  starremarkinput: function(e) { //评价备注
    this.setData({
      starremark: e.detail.value
    })
  },

  pingji_submit: function() { //提交评价
    var that = this
    if (that.data.curstarindex < 4 && that.data.starremark.length == 0) {
      that.setData({
        error: '请填写备注'
      })
      return false
    }
    var param = {
      OperateUserName: wx.getStorageSync('UserInfo').AppLogin.RowGuid,
      OperateDate: dateutil.getNowTime(),
      RowGuid: common.initGuid(),
      WorkOrdersGuid: that.data.RowGuid,
      Score: parseInt(that.data.curstarindex),
      EvaluationDate: that.data.pingjia_time,
      Remark: that.data.starremark,
      CallbackType: '0',
      FileGuid: []
    };
    console.log(param)
    httpRequest.PostValidateRequest(httpRequest.apiInfo.OneClickRepairInfoApi, param,
      function(res) {
        console.log(res)
        if (res == '0') {
          that.setData({
            success: '评价成功'
          })


          var pages = getCurrentPages();
          let prevPage = pages[pages.length - 2];
          if (pages.length > 3) {
            prevPage.setData({
              currentTab: 5,
              state: 4
            })
            wx.navigateBack({
              delta: 1
            })
          } else {
            wx.redirectTo({
              url: '/pages/workorderlist/workorderlist?currentTab=5&state=4&isshoworder=true'
            })
          }


        } else {
          that.setData({
            error: '评价失败'
          })
        }
      },
      function(err) {
        console.error(err)
        that.setData({
          success: '评价失败'
        })
      })
  },

  //获取是否收费
  charge: function(e) {
    console.log(JSON.stringify(e.detail.value))
    this.setData({
      Charges: e.detail.value
    })
  },

  //获取工单撤销原因
  GetKeyWords() {
    var that = this
    var param = {
      CodeName: '撤销原因'
    }
    httpRequest.GetValidateRequest(httpRequest.apiInfo.GetKeyWordsApi, param,
        function(res) {
          console.log('获取工单撤销原因', res)
          that.setData({
            ReasonItems: res
          })
        }),
      function(err) {
        console.error('获取工单撤销原因', err)
      }
  },

  RevokeReasonChange(e) {
    console.log('RevokeReasonChange', e)
    this.setData({
      RevokeCause: e.detail.value
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    console.log(1)
    this.data.RowGuid = options.RowGuid;
    this.initData();
    this.computeScrollViewHeight();
    this.setData({
      pingjia_time: dateutil.getNowDate(),
      DisplayName: wx.getStorageSync("UserInfo").AppLogin.DisplayName,
      OuGuid: wx.getStorageSync("UserInfo").AppLogin.OuGuid
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    console.log(12, this.data.WorkOrderState)


    if (this.data.LeaderGuid_B != '' && this.data.LeaderName_B != '') {
      this.setData({
        dialogShow: true
      })
      console.log(this.data.LeaderGuid_B + '----' + this.data.LeaderName_B)
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})